package com.example.demo.web;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@RequestMapping("/hello")
public class HelloController {

    private static List list = new ArrayList();


    @RequestMapping("/health")
    public String health() {
        return "ok";
    }

    @RequestMapping("/dolphin")
    public Map<String, Object> hello() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", "0");
        map.put("status", 200);
        map.put("timestamp", System.currentTimeMillis());
        map.put("result", "hello dolphin,201808919");
        return map;
    }

    @RequestMapping("/logs")
    public Map<String, Object> testLog4J() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", "0");
        map.put("status", 200);
        map.put("timestamp", System.currentTimeMillis());
        map.put("result", "log");
        return map;
    }

    @RequestMapping("/oom")
    public void oom() {
//        List list = new ArrayList();
        while (true) {
            byte[] test = new byte[1024 * 1024 * 1024 * 256];
            list.add(test);
        }
    }

    @RequestMapping("/logtest")
    public void logtest() {
        for (int i = 0; i < 5; i++) {
            log.error("error测试");
            log.info("infot测试");
            log.debug("debug测试");
        }
    }


    @RequestMapping("/txt")
    public Map<String, Object> getTxt() {
        StringBuffer sb = new StringBuffer();
        int i = 0;
        while (i < 100000){
            sb.append("你好你好|" + i);
            i++;
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", "0");
        map.put("status", 200);
        map.put("timestamp", System.currentTimeMillis());
        map.put("result", sb.toString());

        return map;
    }



}